import { lazy } from "react";
import { createBrowserRouter, Navigate } from 'react-router-dom'
import { isLoggedIn } from '../utils/auth'

// const Home = lazy(() => import('../page/Home/index'))
const Login = lazy(() => import('../page/Login/index'))
const GiteeCallback = lazy(() => import('../page/Login/GiteeCallback'))
// const Message = lazy(() => import('../page/Message/index'))
// const Fen = lazy(() => import('../page/Fen/index'))
// const Index = lazy(() => import('../page/Index/index'))
const App = lazy(() => import('../App'))

// 路由守卫组件
const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
  return isLoggedIn() ? <>{children}</> : <Navigate to="/login" replace />
}

// export const Zi = [
//     {
//         path: '/home',
//         element: <Home></Home>,
//         title: '首页',
//         children: [
//             {
//                 path: '/home/index',
//                 element: <Index></Index>,
//                 title: '模型'
//             },
//             {
//                 path: '/home/message',
//                 element: <Message></Message>,
//                 title: '消息',

//             },

//         ]
//     },
//     {
//         path: '/home/message/fen',
//         element: <Fen></Fen>,
//         title: '分类'
//     }
// ]


const router = createBrowserRouter([
    {
        path: '/',
        element: <ProtectedRoute><App /></ProtectedRoute>,
        // children: Zi
    },
    {
        path: '/login',
        element: <Login />,
    },
    {
        path: '/auth/gitee/callback',
        element: <GiteeCallback />,
    }
])
export default router